import 'package:flutter/services.dart';
import 'package:study_demo/base/BaseController.dart';
import 'dart:ui' as ui;

import 'package:study_demo/res/image.gen.dart';

class CanvasController extends BaseController {
  ui.Image? image;

  @override
  Future<void> onInit() async {
    super.onInit();
    image = await load(ImageRes.yinzhi_log);
    update();
  }

  Future<ui.Image> load(String asset) async {
    ByteData data = await rootBundle.load(asset);
    ui.Codec codec = await ui.instantiateImageCodec(data.buffer.asUint8List(),
        targetWidth: 200, targetHeight: 50);
    ui.FrameInfo fi = await codec.getNextFrame();
    return fi.image;
  }
}
